home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!news
- From: miker3@ix.netcom.com (Mike Rubenstein)
- Newsgroups: comp.lang.c++
- Subject: Re: Help! Macro replacement......
- Date: Fri, 12 Apr 1996 18:42:36 GMT
- Organization: Netcom
- Message-ID: <316e9feb.158491368@nntp.ix.netcom.com>
- References: <4kega2$1tk@hptemp1.cc.umr.edu>
- NNTP-Posting-Host: ix-dc11-06.ix.netcom.com
- X-NETCOM-Date: Fri Apr 12 1:43:10 PM CDT 1996
- X-Newsreader: Forte Agent .99d/32.182
-
- jlu@cs.umr.edu (Eric Jui-Lin Lu) wrote:
-
- >
- > Hi *,
- >
- > I wrote an ugly macro definition which, when I compiled, surprised
- > me. The macro is defined as
- >
- > #define ABS(X) ((X <= 0) ? -X : X)
- >
- > And I called the macro by using
- >
- > int y = ABS(-6+4);
- >
- > I expected y would be 10. However, Solaris CC and Turbo C++ version 3.0
- > for DOS returned compilation error. And IRIX CC and g++ version 2.6.3
- > and 2.7.0 returned 10.
- >
- > The problem is clear that one replacement gives
- >
- > int y = --6+4; // compilation error
- >
- > And the other gives
- >
- > int y = - -6+4; // y = 10
- >
- > I tried to find out the answer from Chap 16 of ANSI C++ standard
- > draft but cannot figure out which one is correct. Will someone
- > please EMAIL me which one conforms to ANSI C++? If interested, I
- > can post the summary. Thanks!
-
- IRIX and g++ are correct. The input is parsed into preprocessor
- tokens before preprocessor directives are executed (draft 2.1).
- #define uses these preprocessing tokens (draft 16.3). It seems that
- the other compilers are doing string substitution before parsing into
- preprocessor tokens.
-
- Michael M Rubenstein
-